<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateOrdersTables extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('orders', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('customer_id')->comment('客户ID');
            $table->unsignedBigInteger('express_id')->comment('快递ID');
            $table->char('code', 18)->unique()->comment('仓单号');
            $table->string('number', 64)->comment('申报订单号');
            $table->string('original_number', 64)->comment('原始订单号; 默认是申报订单号');
            $table->string('express_code', 64)->nullable()->comment('物流单号');

            $table->double('freight', 10, 3)->default(0.0)->comment('物流费');
            $table->double('weight', 10, 3)->default(0.0)->comment('毛重');
            $table->double('net_weight', 10, 3)->default(0.0)->comment('净重');
            $table->double('increase', 10, 3)->default(0.0)->comment('保费');
            $table->double('price', 10, 3)->default(0.0)->comment('货值');

            $table->char('ebc_code', 10)->comment('电商企业代码');
            $table->string('ebc_name', 64)->comment('电商企业名称');
            $table->char('ebp_code', 10)->comment('电商平台代码');
            $table->string('ebp_name', 64)->comment('电商平台名称');

            $table->string('buyer_name', 50)->comment('订购人');
            $table->char('buyer_type', 1)->comment('订购人证件类型');
            $table->string('buyer_number', 50)->comment('订购人身份证号码');
            $table->string('buyer_telephone', 50)->comment('订购人联系方式');
            $table->string('receiving_name', 50)->comment('收件人');
            $table->string('receiving_phone', 50)->comment('收件人电话');
            $table->string('areas', 100)->comment("省市区");
            $table->string('address', 200)->nullable()->comment('详细地址');

            $table->tinyInteger('status')->default(0)->comment('订单状态: -1 取消 0草稿 1确认 2异常 3清关中 4待发货 5已发货');
            $table->tinyInteger('intercept_status')->default(0)->comment('是否拦截: 0 否 1 是');
            $table->string('remark', 255)->nullable();
            $table->timestamps();

            $table->unique(['number', 'customer_id']);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('orders');
    }
}
